<?php

namespace App\Http\Controllers\Export;

use App\Http\Controllers\Controller;
use App\Models\Survey;
use App\Models\SurveyAnswer;
use App\Models\SurveyProblem;
use App\Models\SurveyReply;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;

/**
 * excel导出导入功能
 * 导入乐儿视频数据
 */
class LeerDataExport extends Controller
{

    public $model = null;
    public $replyModel = null;


    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 乐儿数据模板导出
     */
    public function template()
    {
        //设置表头
        $row = [[
            "id" => '序号',
            "type_name" => '所属板块', //也是类型
            "title" => '视频名称',
            "link" => '视频地址',
            "img" => '缩略图地址',
        ]];

        $data = [[
            "id" => '1',
            "type_name" => '汇画', //也是类型
            "title" => '知了',
            "link" => 'https://www.xxx.com/a.mp4',
            "img" => 'https://www.xxx.com/a.jpg',
        ]];

        $title = '乐儿数据导入模板';
        return $this->exportData($data, $title, $row);
    }
    /**
     * 导出数据
     *
     * @param [type] $data
     * @return void
     */
    public function exportData($data, $title, $row)
    {
        $header = $row; //导出表头
        $excel = new Export($data, $header, $title);
        $excel->setColumnWidth(['A' => 10, 'B' => 30, 'C' => 30, 'D' => 20, 'E' => 50, 'F' => 20, 'G' => 20, 'H' => 20, 'I' => 20, 'J' => 20, 'K' => 20, 'L' => 30]);
        $excel->setRowHeight([1 => 30]);
        // $excel->setFreezePane('A2');
        // $excel->setFont(['A1:Z1265' => '宋体']);
        // $excel->setFontSize(['A1:I1' => 14,'A2:Z1265' => 10]);
        // $excel->setBold(['A1:Z2' => true]);
        // $excel->setBackground(['A1:A1' => '808080','C1:C1' => '708080']);
        // $excel->setMergeCells(['A1:I1']);
        // $excel->setBorders(['A2:D5' => '#000000']);
        return Excel::download($excel, $title . '.xlsx');
    }
}
